<template>
	<view class="page-container">
		<view style="border-top: 1px solid #F5F5F5;"></view>
		<uni-segmented-control :current="current" :values="items" style-type="text" active-color="#3679FF" @clickItem="onClickItem" style="background-color: #FFFFFF;" />
		<uni-forms ref="form" :rules="rules" :modelValue="formData">
			<view class="padded-15" v-if="current === 0">
					<view class="font-16 padded-5">基础信息</view>
					<view class="form-container margin-t-5">
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="户籍与居住稳定性" required label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="户籍与居住稳定性" :localdata="domiciles" v-model="formData.domicile" @change="onDomicileChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="职业稳定性" required label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="职业稳定性" :localdata="occupations" v-model="formData.occupation" @change="onOccupationChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
					</view>
					<view class="font-16 padded-5 margin-t-10">信用状态</view>
					<view class="form-container">
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="信用卡/贷款还款情况" label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="信用卡/贷款还款情况" :localdata="repayments" v-model="formData.repayment" @change="onRepaymentChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="近一年征信查询次数" label-width="80" name="credit">
								<uni-easyinput type=number v-model="formData.credit" :inputBorder="false" placeholder="请输入" />
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="行政处罚与司法纠纷情况" label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="行政处罚与司法纠纷情况" :localdata="punishs" v-model="formData.punish" @change="onPunishChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
					</view>
			</view>
			<view class="padded-15" v-else-if="current === 1">
					<view class="font-16 padded-5">经济能力</view>
					<view class="form-container margin-t-5">
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="年收入稳定性"  label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="年收入稳定性" :localdata="year_income_stability_list" v-model="formData.year_income_stability" @change="onDomicileChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="月平均收入"  label-width="135" name="location">
								<uni-easyinput type=number v-model="formData.month_average_income" :inputBorder="false" placeholder="请输入工资、奖金等收入金额" />
							</uni-forms-item>
						</view>
					</view>
					<view class="font-16 padded-5 margin-t-10">资产负债</view>
					<view class="form-container">
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="固定资产情况" label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="固定资产情况" :localdata="fixed_assets_situation_list" v-model="formData.fixed_assets_situation" @change="onRepaymentChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="住房估值" label-width="80" name="credit">
								<uni-easyinput type=number v-model="formData.housing_valuation" :inputBorder="false" placeholder="请输入" />
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="负债率" label-width="135" name="location">
								<uni-easyinput type=number v-model="formData.debt_ratio" :inputBorder="false" placeholder="请输入" />
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="对外担保比例" label-width="135" name="location">
								<uni-easyinput type=number v-model="formData.guarantee_ratio" :inputBorder="false" placeholder="担保余额/净资产比例" />
							</uni-forms-item>
						</view>
					</view>
			</view>
			<view class="padded-15" v-else-if="current === 2">
					<view class="font-16 padded-5">消费能力</view>
					<view class="form-container margin-t-5">
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="信用卡使用率"  label-width="135" name="location">
								<uni-data-picker placeholder="近6个月均消费/授信额度比例" popup-title="信用卡使用率" :localdata="credit_card_list" v-model="formData.credit_card" @change="onDomicileChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="网络借贷情况"  label-width="135" name="location">
								<uni-data-picker placeholder="请选择" popup-title="网络借贷情况" :localdata="online_lending_situation_list" v-model="formData.online_lending_situation" @change="onOccupationChange">
								</uni-data-picker>
							</uni-forms-item>
						</view>
						<view class="border-b-F5F5F5 form-item-view">
							<uni-forms-item label="近一年网贷次数" label-width="135" name="location">
								<uni-easyinput type=number v-model="formData.dk_num" :inputBorder="false" placeholder="请输入" />
							</uni-forms-item>
						</view>
					</view>				
			</view>
			<view class="padded-60"></view>
			<view class="page-bottom clearfix">
				<view class="cancle-btn pull-left">
					<button type="default" class="font-14 bg-FFFFFF padded-t-10 padded-b-10" :data-url="'/pages/index/data_upload'" @click="clickJump">取消</button>
				</view>
				<view class="save-btn pull-left padded-l-10">
					<button type="primary" class="font-14 padded-t-10 padded-b-10" @click="submit">保存</button>
				</view>
			</view>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		onLoad(options) {
			this.getServerData();
			this.getbd();
		},
		data() {
			return {
				items: ['基础信息', '经营与财务', '资产与行业'],
				current: 0,
				formData: {
					domicile: '',
					occupation: '',
					repayment: '',
					credit: '',
					punish: '',
					year_income_stability:'',
					month_average_income:'',
					fixed_assets_situation:'',
					housing_valuation:'',
					debt_ratio:'',
					guarantee_ratio:'',
					credit_card:'',
					online_lending_situation:'',
					dk_num:'',
				},
				rules: {},
				domiciles: [
					{ value: 9,text: "本地户籍且自有住房>=5年" },
					{ value: 6,text: "本地户籍或租房>=3年" },
					{ value: 3,text: "外地户籍且频繁更换住所" },
				],
				occupations: [
					{ value: 9,text: "事业单位/国企工作>=5年" },
					{ value: 6,text: "普通企业工作3-5年" },
					{ value: 3,text: "由职业或工作＜3年" },
				],
				repayments: [
					{ value: 9,text: "近 5 年无逾期记录" },
					{ value: 6,text: "近 5 年 1-2 次逾期且已结清" },
					{ value: 3,text: "近 5 年≥3 次逾期或当前逾期" },
				],
				punishs: [
					{ value: 9,text: "无行政处罚及司法纠纷记录" },
					{ value: 6,text: "存在轻微行政处罚且已处理" },
					{ value: 3,text: "存在重大行政处罚或司法纠纷" },
				],
				year_income_stability_list:[
					{ value: 9,text: "年收入≥50 万且收入稳定" },
					{ value: 6,text: "年收入20 - 50 万且较稳定" },
					{ value: 3,text: "年收入＜20 万或收入波动大" },
				],
				fixed_assets_situation_list:[
					{ value: 9,text: "拥有自有住房且无抵押" },
					{ value: 6,text: "拥有固定资产但存在抵押" },
					{ value: 3,text: "无固定资产或资产价值低" },
				],

				credit_card_list:[
					{ value: 9,text: "信用卡使用率≤50% 且按时还款" },
					{ value: 6,text: "信用卡使用率 50% - 80% 且无逾期" },
					{ value: 3,text: "信用卡使用率＞80% 或存在逾期" },
				],
				online_lending_situation_list:[
					{ value: 9,text: "无网络借贷或仅使用正规平台" },
					{ value: 6,text: "用过网络借贷但无逾期" },
					{ value: 3,text: "频繁使用非正规网络借贷" },
				],
				
				
			}
		},
		methods: {
			getServerData() {
				this.$request().then(res => {
					// 验证登入
				})
			},
			getbd() {
				uni.request({
					url: 'https://wn.wdyky.com/index/jrgl/getgrxq', 
					method: 'GET',
					data: {
					},
					success: (res) => {
						if(res.data.code == 1){ 
							this.formData = res.data.data;
						}
						
						//console.log('GET请求成功：', res.data);
					},
					fail: (err) => {
						console.error('GET请求失败：', err);
					}
				});
			},
			onClickItem(e) {
				this.current = e.currentIndex;
			},
			onDomicileChange(e) {
				console.log('onchange:', e);
			},
			onOccupationChange(e) {
				console.log('onchange:', e);
			},
			onRepaymentChange(e) {
				console.log('onchange:', e);
			},
			onPunishChange(e) {
				console.log('onchange:', e);
			},
			
			submit(){
				//console.log('111111data');
				uni.request({
				    url: 'https://wn.wdyky.com/index/jrgl/grxqsave', // 你的API接口地址
				    method: 'GET',
				    data: {
						data: this.formData,
				    },
				    success: (res) => {
						
						if(res.data.code != 1){
							uni.showToast({
								icon: 'none',
								title: res.data.val
							})
						}
						if(res.data.code == 1){
							uni.showToast({
								icon: 'none',
								title: res.data.val
							})
							uni.navigateBack();
						}
						//console.log('请求成功:', res.data);
				    },
				    fail: (err) => {
				        console.error('GET请求失败：', err);
				    }
				});
				
				
			},
			// 跳转
			clickJump(e){
				uni.navigateBack();
			},
		}
	}
</script>

<style lang="scss">
	@import '@/static/product.scss';
	
	.form-container {
		background: #FFFFFF;
		border-radius: 10px;
		
		.form-item-view {
			padding: 15px 10px;
			
			.uni-forms-item {
				margin: 0;
				padding-right: 10px;
				
				.uni-easyinput__placeholder-class {
					text-align: right;
					color: #999999;
					font-size: 14px;
				}
				
				::v-deep .uni-input-input {
					text-align: right;
				}
				
				::v-deep .input-value-border {
					border: none;
					padding-right: 0;
				}
				
				::v-deep .arrow-area {
					display: none;
				}
				
				::v-deep .selected-area {
					justify-content: flex-end;
					color: #999999;
					font-size: 14px;
				}
				
				::v-deep .selected-list {
					justify-content: flex-end;
				}
			}
		}
	}
	
	.page-bottom {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 15px;
		padding-bottom: 30px;
		background: #FAFAFA;
		
		.cancle-btn {
			width: 90px;
		}
		
		.save-btn {
			width: calc(100% - 90px);
		}
	}
	
</style>
